package sv.com.globalsolutionslt.manejador;

import sv.com.globalsolutionslt.entidades.Departamento;
import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
import sv.com.globalsolutionslt.controlador.DepartamentoFacade;
import sv.com.globalsolutionslt.entidades.Pais;

@Named(value = "departamentoController")
@ViewScoped
public class DepartamentoController extends AbstractController<Departamento> implements Serializable {

    @EJB
    private DepartamentoFacade departamentoFacade;
    private List<Departamento> lDepartamento;

    public DepartamentoController() {
        super(Departamento.class);
    }

    @Override
    public void save(ActionEvent event) {
        this.getSelected().setFechaMod(Calendar.getInstance().getTime());
        this.getSelected().setUsuarioMod(1);
        super.save(event); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void saveNew(ActionEvent event) {
        this.getSelected().setFechaMod(Calendar.getInstance().getTime());
        this.getSelected().setUsuarioMod(1);
        super.saveNew(event); //To change body of generated methods, choose Tools | Templates.
    }

    public List<Departamento> getlDepartamento() {
        lDepartamento = departamentoFacade.DepartamentoActivo();
        return lDepartamento;
    }
    
    
    public List<Departamento> getDepartamentoPorPais(Pais p){
        if(p==null)
            return null;
        return departamentoFacade.obtenerDepartamentosPorPais(p.getIdPais());
    }

}
